<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/jsp/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>信息编辑窗体</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico"> <link href="${ctxStatic}/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/resources/plugins/h+/css/plugins/jsTree/style.min.css" rel="stylesheet">
    <style>
        .jstree-open>.jstree-anchor>.fa-folder:before{content:"\f07c"}.jstree-default .jstree-icon.none{width:0}
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-6">
            <div class="ibox float-e-margins">

                <div class="ibox-content">
                    <form onsubmit="return  false" class="form-horizontal m-t" id="signupForm">
                        <input id="puser_id" value="${puser.user_code}" name="puser.puser_code" type="hidden">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">名称：</label>
                            <div class="col-sm-8">
                                <input id="puser_person_name" value="${puser.person_name}" name="puser.person_name" class="form-control" type="text">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">登录名：</label>
                            <div class="col-sm-8">
                                <input id="puser_login_name" value="${puser.login_name}" name="puser.login_name" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">权限：</label>
                            <div class="col-sm-8">
                                <select id="puser_role_code" value="${puser.role_code}" name="puser.role_code" class="form-control">
                                    <option value=""></option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">手机：</label>
                            <div class="col-sm-8">
                                <input id="puser_phone" value="99" value="${puser.phone}" name="puser..phone" class="form-control" type="number">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">邮箱：</label>
                            <div class="col-sm-8">
                                <input id="puser_email" value="${puser.email}" name="puser.email" class="form-control" type="text">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">备注：</label>
                            <div class="col-sm-8">
                                <input id="puser_notes" value="${puser.notes}" name="puser.notes" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button class="btn btn-primary" onclick="doSubmit();">提交</button>
                                <button id="btn_close"  class="btn btn-primary" type="button">关闭</button>
                              <%--  <button id="transmit"  class="btn btn-primary" type="button">给父页面传值</button>--%>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal inmodal" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated bounceInRight">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                </button>
            选择上级
            </div>
            <div class="modal-body">
                <div class="ibox-content">
<input type="hidden" id="selectPid">
                    <div id="using_json"></div>

                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="doSelect()">选择</button>
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/content.min.js?v=1.0.0"></script>

    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/jsTree/jstree.js"></script>
    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>

<script>

var areaData;
    $(function () {
        loadAgents();
        loadPr();
        loadRole();
     //   $("#using_json").jstree(
          //      {
            //        "core":{"data":["Empty Folder",{"text":"Resources","state":{"opened":true},"children":[{"text":"css","children":[{"text":"animate.css","icon":"none"},{"text":"bootstrap.css","icon":"none"},{"text":"main.css","icon":"none"},{"text":"style.css","icon":"none"}],"state":{"opened":true}},{"text":"js","children":[{"text":"bootstrap.js","icon":"none"},{"text":"hplus.min.js","icon":"none"},{"text":"jquery.min.js","icon":"none"},{"text":"jsTree.min.js","icon":"none"},{"text":"custom.min.js","icon":"none"}],"state":{"opened":true}},{"text":"html","children":[{"text":"layout.html","icon":"none"},{"text":"navigation.html","icon":"none"},{"text":"navbar.html","icon":"none"},{"text":"footer.html","icon":"none"},{"text":"sidebar.html","icon":"none"}],"state":{"opened":true}}]},"Fonts","Images","Scripts","Templates"]}});

    });
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    //parent.layer.iframeAuto(index);
    //让层自适应iframe
    $('#add').on('click', function(){
        $('body').append('插入很多酱油。插入很多酱油。插入很多酱油。插入很多酱油。插入很多酱油。插入很多酱油。插入很多酱油。');

    });
    //给父页面传值
    $('#transmit').on('click', function(){

       // parent(".J_iframe").$("#spancc").text("5");
     //   parent.$('#h5h').html("rfeewewew");
     /*   $(parent.window.frames["iframe8"].document).find("#spancc").html("我被改变了");
        $(parent.window.frames["iframe8"].document).find("#exampleTablePagination").bootstrapTable('refresh');
        //parent.$('#spancc').html('我被改变了');
        parent.layer.close(index);*/
    });

    //关闭iframe
    $('#btn_close').click(function(){
        parent.layer.close(index);
    });
    function selectParents()
    {
        //$("#myModal").model("open");
        /*
        //自定页
        parent.layer.open({
            type: 2,
            shift:4,//动画类型
            moveType:1,
            maxmin: true,
            shadeClose: true, //开启遮罩关闭
            area: ['700px', '530px'],
            content: '${pageContext.request.contextPath}/jsp/basic/agent/agent_list.jsp',
            success: function(layero, index){
                //layer.title("888888888", index);
                var datas={};
                var body = layer.getChildFrame('body', index);
                //var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                console.log(body.html()) //得到iframe页的body内容
            },
            cancel: function(index){
                alert(index);
                return true;
            }
        });*/
    }


    /**
     * 加载代理商列表
     * */
    function loadAgents()
    {
        $.ajax( {
            url:'${pageContext.request.contextPath}/user/getAgentList.ac',// 跳转到 action
            data:{},
            type:'post',
            cache:false,
            dataType:'json',
            success:function(data) {
                treeInit(data);
            },
            error : function() {
                alert("加载代理商列表失败！");
            }
        });
    }

function loadRole()
{
    $.ajax( {
        url:'${pageContext.request.contextPath}/role/getRoleList.ac',// 跳转到 action
        data:{},
        type:'post',
        cache:false,
        dataType:'json',
        success:function(data) {
            var html='<option value="">请选择</option>';
            for(var i=0;i<data.length;i++)
            {

                html+='<option value="'+data[i].id+'">'+data[i].roleName+'</option>';

            }
            $("#puser_role_code").html(html);
            if('${puser.role_code}'!=null&&'${puser.role_code}'!=''&&'${puser.role_code}'!=undefined)
            {
                $("#puser_role_code").val('${puser.role_code}');
            }
        },
        error : function() {
            alert("加载角色列表失败！");
        }
    });
}

    function treeInit(data)
    {
    //   $('#using_json').jstree("destroy");
        $("#using_json").jstree({
            'ui' : {
                'select_parent_open':'true',
                'selected_parent_close' : 'select_parent',

            },
            'core': {
                "check_callback":true,
                'data': data
            },	'themes': {
                'responsive': false,
                'icons' : true,
                'dots	' : false
            },
            "plugins":["types","dnd"],
            "types":{

                "default":{
                    draggable : false, //设置节点不可拖拽
                    "icon":"fa fa-folder"
                }
            }
        }).bind('click.jstree', function(event) {
            var id=$(event.target).parents('li').attr('id');
            $("#selectPid").val(id);
        });
        //$("#using_json").bind("loaded.jstree", function (e, data) {
        //      data.inst.open_all(-1); // -1 打开所有节点
        //  }).jstree();
    }

function doSubmit()
{
    var name=$("#puser_name").val();
    var flag=$("#puser_flag").val();
    var role=$("#puser_role_code").val();
    var sort=$("#puser_sort").val();
    var pro=$("#puser_province").val();
    var city=$("#puser_city").val();
    var isOk=true;
    if(name==null||name==undefined||name==''){alert("请输入名称");isOk= false;}
    if(flag==null||flag==undefined||flag==''){alert("请输入标识");isOk= false;}
    if(role==null||role==undefined||role==''){alert("请选择角色");isOk= false;}
    if(sort==null||sort==undefined||sort==''){alert("请输入排序");isOk= false;}
    if(pro==null||pro==undefined||pro==''){alert("请选择省");isOk= false;}
    if(city==null||city==undefined||city==''){alert("请选择城市");isOk= false;}
if(isOk){
    $.ajax( {
        url:'${pageContext.request.contextPath}/puser/doSave.ac',// 跳转到 action
        data:$("#signupForm").serialize(),
        type:'post',
        cache:false,
        dataType:'json',
        success:function(data) {
           if(data=="success")
           {
               alert("操作成功！");

               parent.layer.close(index);
           }
        },
        error : function() {
            alert("操作失败！");
        }
    });
}
}
</script>

</body>

</html>

